package net.yc.web.imalachat.push.bean.db;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * @author: lyc
 * @data: 2021-12-19  10:17
 * @Description:
 */
@Entity
@Table(name = "TB_GROUP")
public class Group {
    // 这也是一个主键
    @Id
    @PrimaryKeyJoinColumn
    // 主键生成存储的类型为UUID
    @GeneratedValue(generator = "uuid")
    // 把uuid的生成器定义为uuid2，uuid2 时最常规的UUID toString
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    // 不允许更改，不允许为空
    @Column(updatable = false, nullable = false)
    private String id;

    /**
     * 群名称
     * 名字可以一样
     */
    @Column(nullable = false)
    private String name;

    // 群的描述
    @Column(nullable = false)
    private String description;

    // 群的照片
    @Column(nullable = false)
    private String picture;

    @CreationTimestamp
    @Column(nullable = false)
    private LocalDateTime createAt = LocalDateTime.now();

    @UpdateTimestamp
    @Column
    private LocalDateTime updateAt = LocalDateTime.now();

    /**
     * 群的创建者
     * optional：可选为FALSE；必须要有个创建者
     * fetch：加载方式FetchType.EAGER，急加载
     * 意味着加载群的信息的时候必须加载owner的消息
     * cascade：联级级别为all，所有的更新（更新，删除等）都将进行关系更新
     */
    @ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "ownerId")
    private User owner;
    @Column(nullable = false, updatable = false, insertable = false)
    private String ownerId;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public LocalDateTime getCreateAt() {
        return createAt;
    }

    public void setCreateAt(LocalDateTime createAt) {
        this.createAt = createAt;
    }

    public LocalDateTime getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(LocalDateTime updateAt) {
        this.updateAt = updateAt;
    }
}
